<template>
  <view>
    <cu-custom bgColor="bg-blue" :isBack="true">
      <block slot="backText">返回</block>
      <block slot="content">查房登记提交</block>
    </cu-custom>

    <view class="cu-modal" :class="modalName == 'DialogModal2' ? 'show' : ''">
      <view class="cu-dialog">
        <view class="cu-bar bg-white justify-end">
          <view class="content">温馨提示</view>
          <view class="action" @tap="hideModal">
            <text class="cuIcon-close text-red"></text>
          </view>
        </view>
        <view class="">
          <view class="">
            <view class="radius shadow shadow-lg bg-white det_topsss">
              <view class="detail-left detail-inner" style="padding: 0 30rpx">
                服务项目与服务对象不匹配，请确认以后再提交
              </view>
            </view>
          </view>
        </view>
        <view class="cu-bar bg-white justify-end" style="padding: 30rpx 0">
          <view class="action">
            <button
              class="cu-btn line-blue text-green"
              @tap="hideModal('DialogModal2')"
            >
              我知道了
            </button>
            <!-- <button class="cu-btn bg-blue margin-left" @tap="hideModal">提交</button> -->
          </view>
        </view>
      </view>
    </view>

    <view class="cu-modal" :class="modalName == 'DialogModal1' ? 'show' : ''">
      <view class="cu-dialog">
        <view class="cu-bar bg-white justify-end">
          <view class="content">确认登记</view>
          <view class="action" @tap="hideModal">
            <text class="cuIcon-close text-red"></text>
          </view>
        </view>
        <view class="">
          <view class="">
            <view class="radius shadow shadow-lg bg-white det_topsss">
              <view
                class="detail-right detail-inner det_topsss_right"
                style="display: flex; padding-left: 50rpx"
              >
                <view style="margin-right: 30rpx">服务对象</view>
                <view class="detail-content">
                  {{ showItem.preName }}:{{ showItem.name }}
                </view>
              </view>
            </view>
          </view>
        </view>
        <view class="cu-bar bg-white justify-end" style="padding: 30rpx 0">
          <view class="action">
            <button
              class="cu-btn line-blue text-green"
              @tap="hideModal('DialogModal1')"
            >
              取消
            </button>
            <button class="cu-btn bg-blue margin-left" @tap="checkRoom(item)">
              提交
            </button>
          </view>
        </view>
      </view>
    </view>

    <view class="confirms"> 查房信息确认 </view>
    <!-- card -->
    <view class="information" @click="content(item)">
      <view>
        <text>房间:</text>
        <text>{{ title }}</text>
      </view>
      <view>
        <text>查房结果:</text>
        <text v-if="normal == 'true'">正常</text>
        <text v-if="normal == 'false'">异常</text>
      </view>
      <view>
        <text>备注详情:</text>
        <text v-if="item">{{ item }}</text>
        <text v-else>无</text>
      </view>
      <!-- 	<view>
				<text>备注信息</text>
				<text>/无</text>
			</view> -->
      <view>
        <text>查房人:</text>
        <text>{{ nickname }}</text>
      </view>
    </view>
    <view class="bottom">
      <image src="../../../static/img/u35.png" mode=""></image>
      <view
        >您可以将手机背面的NFC扫描区域靠近房卡识别区域完成查房登记操作。</view
      >
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      item: {},//传递
      nickname: "",//查房人
      normal: "true", //checkResult
      title: "",//房间
      params: {},//参数
      roomId: "",////房间id
      showItem: {},//展示的object
      modalName: "",//哪个弹框
      serviceTarget: 1,//房间的标识是1
    };
  },
  onShow() {
    
  },
  onLoad(options) {
    this.item = JSON.parse(options.item);
    this.nickname = uni.getStorageSync("nickname");
    this.normal = options.normal;
    this.title = options.title;
    this.params = JSON.parse(options.params);
    this.roomId = this.params.roomId;

    const that = this;
   uni.$on("NFC_READ", function (msg) {
     that.readCard(msg.rfid);
	});
  },
  onUnload() {
    // 移除监听事件
    uni.$off("NFC_READ");
  },
  
  onHide() {},
  methods: {
	content(item){
		
		// 房间、查房结果、备注详情、查房人
		// 播报按钮播报内容：依次按查房字段和查房信息从上到下进行播报。
		// 信息后面增加一句：如您已确认信息无误，马上刷卡完成查房登记操作吧。
		 if(this.normal=='true'&&this.item){
			if(this.$store.state.state&&this.$store.state.isphone){
				getApp().globalData.TTSSpeaker.stop();
				getApp().globalData.TTSSpeaker.speak('房间'+this.title+'查房结果正常备注详情'+this.item+'查房人'+this.nickname+'如您已确认信息无误，马上刷卡完成查房登记操作吧。',1);
			} 
		 }else if(this.normal=='true'&&this.item=={}){
			 if(this.$store.state.state&&this.$store.state.isphone){
			 	getApp().globalData.TTSSpeaker.stop();
			 	getApp().globalData.TTSSpeaker.speak('房间'+this.title+'查房结果正常备注详情无查房人'+this.nickname+'如您已确认信息无误，马上刷卡完成查房登记操作吧。',1);
			 } 
		 }else if(this.normal=='false'&&this.item){
			 if(this.$store.state.state&&this.$store.state.isphone){
			 	getApp().globalData.TTSSpeaker.stop();
			 	getApp().globalData.TTSSpeaker.speak('房间'+this.title+'查房结果不正常备注详情'+this.item+'查房人'+this.nickname+'如您已确认信息无误，马上刷卡完成查房登记操作吧。',1);
			 } 
		 }else if(this.normal=='false'&&this.item=={}){
			 if(this.$store.state.state&&this.$store.state.isphone){
			 	getApp().globalData.TTSSpeaker.stop();
			 		getApp().globalData.TTSSpeaker.speak('房间'+this.title+'查房结果正常备注详情无查房人'+this.nickname+'如您已确认信息无误，马上刷卡完成查房登记操作吧。',1);
			 } 
		 }
	},
    readCard(id) {
      this.$http(
        "/implement-service/implement/getByRfidCardIdForService",
        "get",
        {
          rfidCardId: id,
        }
      ).then((res) => {
        if (res.data.code == 200) {
          let data = res.data.data;
          if (data == undefined) {
			if(this.$store.state.state&&this.$store.state.isphone){
				getApp().globalData.TTSSpeaker.stop();
				getApp().globalData.TTSSpeaker.speak('这是个空标签。',1);
			}	
          } else if (data.serviceTarget == this.serviceTarget && data.serviceObject.id == this.roomId) {
            this.showItem = res.data.data.serviceObject;
            // this.showModal("DialogModal1");
			// this.realSubmit(this.item);
			this.checkRoom();
          } else {
            this.showItem = res.data.data.serviceObject;
			if(this.$store.state.state&&this.$store.state.isphone){
				getApp().globalData.TTSSpeaker.stop();
				getApp().globalData.TTSSpeaker.speak('服务项目与服务对象不匹配。',1);
			}	
			uni.showToast({
			    title: '服务项目与服务对象不匹配',
				icon:'none',
			    duration: 1500,
			});
          }
        }
      });
    },
    // POST /checkRoom/save
    // 保存查房登记
    checkRoom() {
		// this.hideModal("DialogModal1");
      let param = {
        checkInfo: this.item,
        checkResult: this.normal,
        roomId: this.roomId,
        teamId: uni.getStorageSync("teamId"),
      };
      this.$http("/care-service/checkRoom/save", "post", param).then((res) => {
        if (res.data.code == 200) {
		  // if(this.$store.state.state&&this.$store.state.isphone){
		  // 	getApp().globalData.TTSSpeaker.stop();
		  // 	getApp().globalData.TTSSpeaker.speak(' 您已完成XX房间的日常查房工作，您辛苦了，快休息下吧。',1);
		  // }	
		  if(this.$store.state.state&&this.$store.state.isphone){
		  	getApp().globalData.TTSSpeaker.stop();
		  	getApp().globalData.TTSSpeaker.speak('刷卡提交成功。',1);
		  }	
		  uni.showToast({
		      title: '刷卡提交成功',
		  	icon:'none',
		      duration: 1500,
		  });
          setTimeout(function(){
          	uni.switchTab({
          	    url: '/pages/basics/index'
          	});
          },1500)
        } else {
          // this.hideModal("DialogModal1");
        }
      });
    },
    showModal(item) {
      this.modalName = item;
      if (item == "DialogModal1") {
      } else if (item == "DialogModal2") {
      }
    },
    hideModal(e) {
      this.modalName = null;
    },
  },
};
</script>
<style scoped lang="scss">
page {
  color: #666;
}

.bottom {
  padding: 20rpx 40rpx;
  display: flex;

  view {
    flex: 1;
    padding-left: 20rpx;
    font-size: 30rpx;
  }

  :nth-child(1) {
    width: 40rpx;
    height: 40rpx;
  }
}

.confirms {
  font-size: 34rpx;
  padding: 20rpx 30rpx;
}

.information {
  background-color: #fff;
  font-size: 30rpx;
  padding: 20rpx 30rpx;

  view {
    text:nth-child(1) {
      margin-right: 12rpx;
    }
  }
}
</style>
